package com.liu.concurrent.juc;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class CompletableFutureDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //发起一个异步请求
        CompletableFuture<Void> runAsync = CompletableFuture.runAsync(()->{
            System.out.println(Thread.currentThread().getName());
        });
        // 获取阻塞执行结果
        runAsync.get();

        //发起一个异步请求,有返回值
        CompletableFuture<Integer> supplyAsync = CompletableFuture.supplyAsync(()->{
            System.out.println(Thread.currentThread().getName());
            return 1024;
        });
        supplyAsync.get();

    }
}
